﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuxiWTO.Mapping;
using WutiWTO.Common;

namespace WuxiWTO.Web
{
    public partial class enterpriseComplain : System.Web.UI.Page
    {
        WTODataContext ctx = new WTODataContext();
        PagedDataSource psd = new PagedDataSource();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user_name"] == null && Request.Cookies["wtouser"] == null)
            {
                Response.Redirect(Server.HtmlEncode("login.aspx?ret=enterpriseComplain.aspx"));
            }
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        private void BindGrid()
        {
            string pid = Session["user_id"].ToString();
            if (!string.IsNullOrEmpty(pid))
            {
                int intPid = int.Parse(pid);

                var query = (from c in ctx.Complaints orderby c.update_date descending where c.supporter_id == intPid select c).AsQueryable();
              
                List<Complaint> list = query.ToList();
                AspNetPager1.RecordCount = list.Count; ;
                psd.DataSource = list;
                psd.AllowPaging = true;
                psd.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                psd.PageSize = AspNetPager1.PageSize;

                this.rptArticle.DataSource = psd;
                this.rptArticle.DataBind();
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "paraerr", "alert('参数传递错误');location='default.aspx';", true);
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid();
        }
        protected void rptArticle_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var item = e.Item.DataItem;
                Complaint cat = item as Complaint;

                Label lblCom = e.Item.FindControl("lblStatus") as Label;
                string status = "";
                switch (cat.record_status)
                {
                    case 'N': status = "已提交"; break;
                    case 'R': status = "已受理"; break;
                    case 'P': status = "已处理"; break;
                }
                lblCom.Text = status;
            }
        }
    }
}